/**
 * Copyright [2019] [LiBo/Alex of copyright liboware@gmail.com ]
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.asciidoctor.swagger.handler.impl;

import com.hyts.asciidoctor.swagger.handler.SwaggerTransferHandler;
import com.hyts.asciidoctor.swagger.bean.UrlTransferBean;
import io.github.swagger2markup.Swagger2MarkupConfig;
import io.github.swagger2markup.Swagger2MarkupConverter;
import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder;
import io.github.swagger2markup.markup.builder.MarkupLanguage;

import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Paths;

/**
 * @project-name:coffice-toolbox
 * @package-name:com.hyts.swagger.handler.impl
 * @author:LiBo/Alex
 * @create-date:2019-08-19 13:24
 * @copyright:libo-alex4java
 * @email:liboware@gmail.com
 * @description:
 */
public class PdfUrlTransferHandler implements SwaggerTransferHandler<UrlTransferBean,Void> {


    @Override
    public Void transfer(UrlTransferBean param) {
        //    输出Ascii格式
        Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
                .withMarkupLanguage(MarkupLanguage.ASCIIDOC)
                .build();
        try {
            Swagger2MarkupConverter.from(new URL(param.getSwaggerJsonUrl()))
                    .withConfig(config)
                    .build()
                    .toFile(Paths.get(param.getOutputFilePath()));
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args){
        new PdfUrlTransferHandler().transfer(new UrlTransferBean(
                "http://r3.burgeon.cn:32940/v2/api-docs","src/docs/asciidoc/generated/all"));

    }

}
